
import time
# 导入系统资源模块
from ascript.android.system import R
# 导入动作模块
from ascript.android import action
# 导入节点检索模块
from ascript.android import node
# 导入图色检索模块
from ascript.android import screen
from ascript.android.ui import Loger
from . import watch_orc
from ascript.android.ui import WebWindow
from ascript.android.system import R
import json

class Diemaomao:
    def __init__(self):
        self.ui_flag = False
        self.default_ad_time = 5 * 60
        self.default_fun_list = ["auto_ad"]


    def tunner(self,k,v):
        print(k,v)
        self.ui_flag =  True
        if k=="submit":
            data = json.loads(v)
            ad_time = int(data["ad_time"])*60
            watch_orc.start(ad_time,data["fun_list"])
    def start(self,):
        try:
            w = WebWindow(R.ui('index.html'), self.tunner)
            w.show()
        except Exception as e:
            print(e)
            time.sleep(10)
            watch_orc.start(self.default_ad_time, self.default_fun_list)

        time.sleep(20)
        print(3333333333333333333,self.ui_flag)
        if self.ui_flag==False:
            try:
                w.close()
            except:
                pass
            time.sleep(10)
            watch_orc.start(self.default_ad_time,self.default_fun_list)

Diemaomao().start()


# ad_item_bos = node.Selector().path("/FrameLayout/ViewGroup/ViewGroup/ViewGroup").find()
# if ad_item_bos:
#     ad_item_bos.click()
#     print("================close tem")


